package net.uhuijia.sys.area.controller;

import net.uhuijia.enums.AreaLevel;
import net.uhuijia.sys.area.persistence.model.SysArea;
import net.uhuijia.sys.area.persistence.model.SysAreaExample;
import net.uhuijia.vo.ResultMapVo;
import net.uhuijia.vo.ReturnListVo;
import net.uhuijia.vo.sys.area.AreaVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import net.uhuijia.appbase.controller.BaseController;
import net.uhuijia.sys.area.service.SysAreaService;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping(value="/area")
public class SysAreaController
     extends BaseController<SysAreaService,SysArea,SysAreaExample> {
    @Autowired
    private SysAreaService sysAreaService;

    /**
     * @Author xzj
     * @Description //根据parentId和城市等级查询城市列表
     * @Date  2018/10/8
     * @Param
     * @return
     **/
    @RequestMapping(value = "/areaList")
    @ResponseBody
    public ResultMapVo<ReturnListVo<AreaVo>> areaList(String parentId, Integer level ){
        AreaLevel areaLevel =null;
        if(level==null|| (areaLevel = AreaLevel.getAreaLevel(level))==null)
            throw new  IllegalArgumentException();
        if(AreaLevel.province.getLevel()!=level.intValue() && StringUtils.isEmpty(parentId))
            throw new  IllegalArgumentException();
        List<AreaVo> areaVos  = this.sysAreaService.findAreaVoByParentIdAndAreaLevel(parentId,areaLevel);
        return ResultMapVo.ok(new ReturnListVo<>(areaVos));
    }

}